package com.axis2.common.util;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author yemulin
 * @create 2012-8-20 上午10:49:57
 */
public class Form {

	private String name = "sendOrder";
	private String id = "sendOrder";
	private String method = "post";
	private String action;

	private String autoSubmitScritp = "<script language='javascript'>setTimeout(\"document.getElementById('sendOrder').submit();\",500);</script>";

	Map<String, String> inputMap = new LinkedHashMap<String, String>();

	// 向form添加一个隐藏域元素
	public void addInput(String name, String value) {
		inputMap.put(name, value);
	}

	public String getFormStr() {
		StringBuilder formStr = new StringBuilder();
		// form开始
		formStr.append("<form ");
		formStr.append("name=\"").append(name).append("\" ");
		formStr.append("id=\"").append(id).append("\" ");
		formStr.append("method=\"").append(method).append("\" ");
		formStr.append("action=\"").append(action).append("\" >");

		Iterator<Entry<String, String>> it = inputMap.entrySet().iterator();
		while (it.hasNext()) {
			Entry<String, String> inputEntry = it.next();
			formStr.append("<input type=\"hidden\" name=\"")
					.append(inputEntry.getKey()).append("\" value=\"")
					.append(inputEntry.getValue()).append("\">");
		}
		// form结束
		formStr.append("</form>");
		// 添加自动提交脚步
		formStr.append(autoSubmitScritp);

		return formStr.toString();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public Map<String, String> getInputMap() {
		return inputMap;
	}

	public void setInputMap(Map<String, String> inputMap) {
		this.inputMap = inputMap;
	}

	public String getAutoSubmitScritp() {
		return autoSubmitScritp;
	}

	public void setAutoSubmitScritp(String autoSubmitScritp) {
		this.autoSubmitScritp = autoSubmitScritp;
	}

}
